package everyday;

/**
 * @author ZhanBo
 * @date 2020/6/19
 */
public class Solution125 {
    public static void main(String[] args) {
        String a= "A man, a plan, a canal: Panama";
//        char x ='1';
//        char y = '1';
//        System.out.println(isEqual(x, y));
        System.out.println(isPalindrome(a));

    }


    /**
     * 125. 验证回文串
     * 给定一个字符串，验证它是否是回文串，只考虑字母和数字字符，可以忽略字母的大小写。
     *
     * 说明：本题中，我们将空字符串定义为有效的回文串。
     *
     * 输入: "A man, a plan, a canal: Panama"
     * 输出: true
     * @param s
     * @return
     */
    public static boolean isPalindrome(String s) {
        StringBuffer sgood = new StringBuffer();
        int length = s.length();
        for (int i = 0; i < length; i++) {
            char ch = s.charAt(i);
            if (Character.isLetterOrDigit(ch)) {
                sgood.append(Character.toLowerCase(ch));
            }
        }
        int n = sgood.length();
        int left = 0, right = n - 1;
        while (left < right) {
            if (Character.toLowerCase(sgood.charAt(left)) != Character.toLowerCase(sgood.charAt(right))) {
                return false;
            }
            ++left;
            --right;
        }
        return true;
    }

    public static boolean isOK(char a){
        if (a >=65 && a<=90 || a>=97 && a<=122 || a>=48 && a<=57){
           return true;
        }
        return false;
    }

    public static boolean isEqual(char a , char b){
        if (a == b){
            return true;
        }
        if (a - b ==32 || a - b == -32){
            return true;
        }
        return false;
    }
}
